package edu.mju.dao;

import edu.mju.bean.Role;
import edu.mju.mapper.RoleMapper;
import edu.mju.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;

public class RoleDao {

    public int insertRole(Role role) throws IOException {
        SqlSession session = MyBatisUtil.getSession();
        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
        int i = roleMapper.insertRole(role);
        //int i = session.insert("edu.mju.mapper.RoleMapper.insertRole",role);
        session.commit();
        session.close();
        return  i;
    }

    public Role selectRoleById(Integer id){
        SqlSession session = MyBatisUtil.getSession();
        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
        Role role = roleMapper.selectRole(id);
        session.close();
        return role;
    }

    public int deleteRole(Integer id){
        SqlSession session = MyBatisUtil.getSession();
        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
        int i = roleMapper.deleteRole(id);
        session.commit();
        session.close();
        return i;
    }

    public int updateRole(Role role){
        SqlSession session = MyBatisUtil.getSession();
        RoleMapper roleMapper = session.getMapper(RoleMapper.class);
        int i = roleMapper.updateRole(role);
        session.commit();
        session.close();
        return i;
    }



   
}
